<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>答题闯关王</title>
    <link rel="shortcut icon" href="__STATIC__/favicon.ico"/>
    <link href="__STATIC__/css/index/index.css" type="text/css" rel="stylesheet">
	<link href="__STATIC__/layui/css/layui.css" type="text/css" rel="stylesheet">
    <link href="__STATIC__/css/index/iconfont/iconfont.css" type="text/css" rel="stylesheet">
	<script src="__STATIC__/layui/layui.all.js" type="application/javascript"></script>
	<style>
		.desktop .order-box table tbody tr td{
			text-align: center;
		}
	</style>
</head>
<body>
	<div class="desktop item-wrapper">
		<div class="desktop-main">
			<div class="order-box">
				<div class="layui-form-item">
					<button type="button" class="layui-btn layui-btn-sm" onclick="add()" style="float: right;margin-right: 40px; margin-top: 3px;" >
						本项最多8个<i class="layui-icon">&#xe608;</i> 添加
					</button>
				</div>
				<table cellspacing="0" ng-show="docArr.length>0">
					<thead>
						<tr>
							<td>id</td>
							<td>奖项物品名称</td>
							<td>抽奖概率</td>
							<td>操作</td>
						</tr>
					</thead>
					<tbody id="order-table">
					<?php $num=0;?>
					{foreach $data as $value}
						<tr>
							<td>{++$num}</td>
							<td><input type="text" name="prize_name" value="{$value['prize_name']}"></td>
							<td><input type="text" name="Lottery_probability" value="{$value['Lottery_probability']}"></td>
							<td>
								<input type="button" class="layui-btn layui-btn-xs" value="保存" onclick="btn(this,'{$value['id']}')">
							</td>
						</tr>
					{/foreach}
					</tbody>
					<tfoot >
						<tr >
							<form id=addForm' type="post">
								{volist name="ares" id="ares"}
									<td >抽奖次数</td>
									<td style="text-align: center;" ><input type="text" name="frequency" id="aq" value="{$ares.frequency}"></td>
									<td style="text-align: center;"><input type="button" class="layui-btn layui-btn-xs" value="保存" onclick="btn2()"></td>
								{/volist}
							</form>
						</tr>
					</tfoot>
				</table>
			</div>
		</div>
	</div>
</body>
<script src="/static/js/jquery-3.3.1.js"></script>
<script src="/static/js/maowenke.js"></script>
<script>
	function add() {
        layer.open({
            type: 2,
            title: '添加抽奖',
            shadeClose: true,
            shade: false,
            maxmin: true, //开启最大化最小化按钮
            area: ['893px', '600px'],
            content: "{:url('luck/show_add')}"
            ,end:function () {
                window.location.reload();
            }
        });
    }
function btn(obj,$id) {
    var $prize_name = $(obj).parents('tr').find("[name=prize_name]").val();
    var $Lottery_probability = $(obj).parents('tr').find("[name=Lottery_probability]").val();
    $.post("{:url('luck/update')}",{id:$id,prize_name:$prize_name,Lottery_probability:$Lottery_probability},function (data) {
		if(data==1){
		    layer.msg('更新成功');
		}else{
		    layer.msg(data);
		}
    });
}
function btn2() {
	var frequency = $("#aq").val();
	$.ajax({
		url:"{:url('Form/dao')}",
		type:"post",
		data: {frequency:frequency},
		success:function(result){
			 if (result = 1) {
				layer.msg('修改成功');
			 }else{
				layer.msg('添加失败');
			 } 
		}
	})
}
</script>
</html>